package com.globallogic.run;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class AppSettings {

	private static final String settingsFileName = "JavaDraw.properties";
	private static final String outputFileName = "OutputFileName";  
	private static final String log4jFileName = "log4jFileName";
	
	public static String getOutputFileName() {
		
		final String defOutput = "JDrawOutput.txt";
		
		return appProperties.getProperty(outputFileName, defOutput);
		
	}

	public static String getLog4jFileName() {
		
		return appProperties.getProperty(log4jFileName);
		
	}
	
	private static Logger getLogger() {
        
		BasicConfigurator.configure();
		return Logger.getLogger(AppSettings.class);
		
	}
	
	private static Properties getAppProperties() {

		Properties properties = new Properties();

		try {
			
			FileInputStream in = new FileInputStream(settingsFileName); 
			
			properties.load(in);
			in.close();
			
		} catch (FileNotFoundException e) {
		
			logger.error("Settings file " + settingsFileName + " not found", e);
			
		} catch (IOException e) {

			logger.error("Error while reading settings file: " + settingsFileName, e);
			
		} 
		
		return properties;
		
	}
	
    private static Logger logger = getLogger();
	private static Properties appProperties = getAppProperties();

}
